home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Tools & Utilities
/
Collection of Tools and Utilities.iso
/
batchut
/
strings2.zip
/
STRINGS.DOC
< prev
next >
Wrap
Text File
|
1992-11-25
|
49KB
|
1,080 lines
STRINGS.COM (Version 2.0) Copyright (c) 1991, 1992 Douglas Boling
-------------------------------------------------------------------------
First Published in PC Magazine December 22, 1992 (Utilities)
-------------------------------------------------------------------------
STRINGS:
The original STRINGS.COM removed the restrictions imposed by the DOS
batch file language to give your batch files more versatility. This upgraded
TSR version enhances a number of the original functions and implements more
than 35 new ones.
Batch Files Get Even Better With Our STRINGS 2.0
BY DOUGLAS BOLING
The new version contains not only the batch file commands of the
original utility, but 6 enhanced functions and 35 new ones as well.
In all, as shown in Figure 1 (below) STRINGS now adds about 70 commands
to the batch file language. (Some of these commands can be used from
the DOS prompt as well.) Where the original STRINGS let you add a series
of numbers, read a line from a file, or ask a user a question,
STRINGS 2.0 includes additional functions that allow batch files to
query the date and time, get the current country and codepage, and even
read and write to memory locations.
Perhaps the outstanding new feature of STRINGS 2.0 is that under
DOS 3.3 or later it can now act as an extension to the DOS command
processor, COMMAND.COM. This required rewriting the program so it could
become a TSR.
Once memory resident, since COMMAND.COM no longer has to search,load, and run the program, STRINGS's commands execute with the same speed
as do such internal COMMAND.COM functions as COPY, RENAME, and DELETE.
The new program itself bears the same name, STRINGS.COM, as its
predecessor. That allows you to upgrade instantly simply by copying the
new program over the old. To avoid confusion, I will refer to the original
version of the utility as STRINGS1. If you have never used STRINGS1,
reading through the original article will be helpful, but I'll try to
explain enough here to make that unnecessary.
To assemble the source you will need an assembler compatible with
Microsoft's MASM 2.0. The commands to create STRINGS.COM are:
MASM STRINGS;
LINK STRINGS;
EXE2BIN STRINGS STRINGS.COM
USING STRINGS
At first sight, the complete syntax for STRINGS.COM may seem
dauntingly complex:
STRINGS [/?][/M][/Q][/Pc][/Bn][/I][/U] [env var =] FUNCTION [Params]
But it's a lot easier to use than it looks. One reason is that, in
addition to this article, the on-screen help facilities are extensive.
Simply enter STRINGS at the DOS prompt and you'll get an explanation of
every item in the syntax line above. Entering STRINGS /? will give you a
complete list of all the commands denoted by FUNCTION, and
STRINGS /? FUNCTION
will spell out the purpose, usage, and Prams (parameters) of each
individual command. Note that in both of these last two commands the
/? can be replaced by /HELP.
Many STRINGS commands require no arguments; for these you just enter
STRINGS FUNCTION
For example, to return the last available drive letter you simply enter:
STRINGS LASTDRIVE
STRINGS will respond by displaying the last available drive letter on
your system.
For commands that do take input parameters, the arguments are
separated by commas. For example, the command LEFT, which returns the
first n characters (including spaces) of a string, has two parameters:
the input string and the number of characters to return. Thus,
STRINGS LEFT This is a string, 9
will return the left nine characters ``This is a". Note the comma
separating the two parameters in the command line.
The results of any STRINGS command can be assigned to an environmentvariable. Simply insert the name for the variable and an equals sign
between STRINGS and FUNCTION. For example, by changing the previous
example to
STRINGS ANSWER =LEFT This is a string, 9
STRINGS will assign the string ``This is a'' to the environment variable
ANSWER.
As shown above, STRINGS has seven command line switches:
/M, /Pc, /Q, /Bn, /I, /U and /?. The switch must be included on the
command line before the environment variable or, if no variable is
specified, before the command.
By default, STRINGS stores variables in the Active environment,
which is created by the current copy of COMMAND.COM. If the /M switch
is used, however, STRINGS stores variables in the master environment,
which is created by COMMAND.COM when DOS starts.
In Windows, while each DOS box has its own Active environment, all
share the Master environment. By using the /M switch, variables can be
read by all programs, including those in individual Windows DOS boxes.
The /M switch is also useful when you want to preserve a variable
assignment you make while shelled out from a program, for the local
environment is lost when you exit from DOS back into your application.
Reverting to the previous example, to assign the results to the
environment variable RESULT in the Master environment, the command would
be
STRINGS /M RESULT = LEFT This is a string, 9
The MASTERVAR command returns the string assigned to a variable inthe Master environment. For example, the command
STRINGS MASTERVAR RESULT
returns the string assigned to the RESULT environment variable even if
this command is executed in a different DOS box from the one that was
used in previous examples!
The /Pc (or Parse) switch tells STRINGS to use the c character
rather than the comma to separate multiple parameters. This switch
allows you to work with strings that contain commas.
The /Q (or Quiet) switch, which was added in a maintenance release
of STRINGS 1.0, prevents STRINGS from writing to the screen. This switch
is useful if the STRINGS command may produce an error message that you
don't want displayed on the screen.
New in STRINGS 2.0 is the /Bn switch, which is used to change the number
base that STRINGS uses to interpret numbers. STRINGS defaults to base 10
arithmetic, but by using the /B switch, you can set the base to any number
from 2 to 16. Thus, while the statement
STRINGS ADD 9, 1
returns the standard value 10, the statement
STRINGS /B16 ADD 9, 1
returns the ``number'' A, since A in hexadecimal (base 16) is 10 in decimal.
You'll want to use the /B switch working with several of the new STRINGS
commands, where it is more appropriate to use hexadecimal than decimal
numbers.
If your system is running DOS 3.3 or later, using the /I switch installs
STRINGS as a resident extension of COMMAND.COM. (How STRINGS actuallyaccomplishes this will be discussed later.) Unlike most TSRs, which are
installed at startup, STRINGS works best if it is installed only when
and for as long as needed; it should be removed from memory once the
batch file has completed in order to avoid wasting valuable systemmemory. To uninstall STRINGS, you simply use the /U switch.
Installing STRINGS as a resident extension does not alter the syntax
of any of its commands. The speed advantage is dramatic. The disadvantage,
however, is that once installed, STRINGS (like all internal COMMAND.COM
commands) cannot return an exit code to COMMAND.COM. This means that
while STRINGS is resident, you can't use the handy IF ERRORLEVEL statement
in .BAT files to test the result of STRINGS commands.
If your batch file requires the error level codes returned by STRINGS,
two solutions are available. The first and most obvious is simply not
to install STRINGS at the start of the batch file. When not installed,
STRINGS 2.0 returns the same error codes as STRINGS 1.0.
The second solution is to sp